<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
    <title>骏丰科技</title>
    <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
    <script src="./mainAssets/jquery-3.7.1.min.js"></script>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/main.ts"></script>
    <script>
      // 禁止浏览器上下滑动
      document.body.addEventListener('touchmove', function (e) {
        e.preventDefault();
      }, { passive: false }); // 注意：passive: false 在 iOS 上至关重要
    </script>
    <script async="">
      // 存储 openid 和用户信息到 localStorage
      function storeUserInfo(openid, nickname, avatar) {
        localStorage.setItem('openid', openid)
        localStorage.setItem('nickname', nickname)
        localStorage.setItem('avatar', avatar)
      }
      function getUserInfo() {
        const openid = getUrlParameter('openid') || localStorage.getItem('openid')
        const nickname = getUrlParameter('nickname') // 获取 'code' 参数的值
        if (openid) {
          localStorage.setItem('openid', openid)
          // 如果 localStorage 有 openid，说明用户已授权，走其他逻辑
          const nickname = localStorage.getItem('nickname')
          const avatar = localStorage.getItem('avatar')
          // 处理其他逻辑，例如展示用户信息
          console.log('User Info:', { openid, nickname, avatar })
          $.ajax({
            url: 'https://api.vtogether.net/other/getInfoByOpenidJfqzh', // 接口的 URL
            type: 'GET', // 请求类型 (GET, POST, etc.)
            dataType: 'json', // 预期返回的数据类型
            data: {
              openid: openid // 请求参数
            },
            success: function (res) {
              // 请求成功时的回调函数
              console.log('数据获取成功:', res)
              // 在这里处理成功获取的数据
              localStorage.setItem('nickname', res.data.nickname)
              localStorage.setItem('avatar', res.data.headimgurl)
            },
            error: function (jqXHR, textStatus, errorThrown) {
              // 请求失败时的回调函数
              console.error('请求失败:', textStatus, errorThrown)
              // 在这里处理错误
            }
          })
        } else {
          // 如果没有 openid，调用授权接口获取用户信息
          // redirectToAuth()
        }
      }

      function getUrlParameter(name) {
        const urlParams = new URLSearchParams(window.location.search)
        return urlParams.get(name)
      }

      // 引导用户授权获取 openid 的函数
      function redirectToAuth() {
        // const appId = 'YOUR_APPID';
        const redirectUri = encodeURIComponent(window.location.href) // http%3A%2F%2F127.0.0.1%3A7001%2Findex.html
        const authUrl = `https://api.vtogether.net/other/getUserInfoJfqzh?redirect_url=${redirectUri}`
        window.location.href = authUrl
      }
      document.addEventListener('DOMContentLoaded', () => {
        getUserInfo()
      })
    </script>
  </body>
</html>